Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: RelationshipJoiner raw & sub-query orders #15261

Merged
merged 9 commits into from
Jan 22, 2025

Conversation

ralphjsmit
Copy link
Contributor

This PR fixes two situations in the RelationshipJoiner that did not work:

  • ->orderByRaw("CASE WHEN role = 'PIC' THEN 1 ELSE 2 END")
  • ->orderBy(fn (Builder $query) => $query->selectRaw("CASE WHEN role = 'PIC' THEN 1 ELSE 2 END"))

This PR fixes both cases to make the RelationshipJoiner handle them correctly. There might always be edge cases regarding this part of the RelationshipJoiner, like when the raw order by contains a binding, but at least this makes the joiner handle a few more common cases.

@danharrin danharrin added the bug Something isn't working label Jan 6, 2025
@danharrin
Copy link
Member

The code looks great, but would you mind writing some tests for this? It's getting to a point where the conditions are quite complex and I would hate for them to break in the future.

@danharrin danharrin modified the milestones: v2, v3 Jan 6, 2025
@ralphjsmit
Copy link
Contributor Author

Yes, sure! Will do later this week.

@ralphjsmit
Copy link
Contributor Author

ralphjsmit commented Jan 15, 2025

@danharrin I just added tests for the RelationshipJoiner, and also confirmed that it failed on the old code just to be sure.

@danharrin danharrin merged commit 4c850f0 into filamentphp:3.x Jan 22, 2025
10 checks passed
@danharrin
Copy link
Member

Thanks Ralph!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants